using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Xml.Serialization;
using WozLib.UI.Ink.SketchObjects;

namespace WozLib.UI.Ink.SketchProperties
{
  public class RectGeometrySketchProperty : SketchProperty
  {

    [XmlElement("Rect")]
    public Rect Rect
    {
      get { return _Rect; }
      set 
      {
        if (_Rect != value)
        {
          _Rect = value;

          FirePropertyChanged("Rect");
          FirePropertyChanged("Left");
          FirePropertyChanged("Top");
          FirePropertyChanged("Height");
          FirePropertyChanged("Width");
          NotifyPropertyChanged();
        }
      }
    } private Rect _Rect;

    [XmlIgnore]
    public double Left
    {
      get 
      {
        return Rect.X;
      }
      set 
      {
        if (Rect.X != value)
        {
          _Rect.X = value;

          FirePropertyChanged("Left");
          NotifyPropertyChanged();
        }
      }
    }

    [XmlIgnore]
    public double Top
    {
      get
      {
        return Rect.Y;
      }
      set
      {
        if (Rect.Y != value)
        {
          _Rect.Y = value;

          FirePropertyChanged("Top");
          NotifyPropertyChanged();
        }
      }
    }

    [XmlIgnore]
    public double Width
    {
      get
      {
        return Rect.Width;
      }
      set
      {
        if (Rect.Width != value)
        {
          _Rect.Width = value;

          FirePropertyChanged("Width");
          NotifyPropertyChanged();
        }
      }
    }

    [XmlIgnore]
    public double Height
    {
      get
      {
        return Rect.Height;
      }
      set
      {
        if (Rect.Height != value)
        {
          _Rect.Height = value;

          FirePropertyChanged("Height");
          NotifyPropertyChanged();
        }
      }
    }


    public RectGeometrySketchProperty(Rect rect, WozPropertyType wozPropertyType)
      : base(wozPropertyType)
    {
      Rect = rect;
    }

    public RectGeometrySketchProperty()
      : base()
    {
    }

    public override object Clone()
    {
      return new RectGeometrySketchProperty(Rect, this.WozPropertyType);
    }

    /// <summary>
    /// Returns true if .equals on the Data is true
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public override bool Equals(object obj)
    {
      if (obj is RectGeometrySketchProperty && (obj as RectGeometrySketchProperty).Rect == Rect)
      {
        return true;
      }
      else
      {
        return false;
      }
    }

    public override CascadingProperty CreateCascadingProperty(List<ISketchObject> iWozObjects)
    {
      return new RectGeometryCascadingProperty(iWozObjects, this);
    }
  }
}
